package com.li.springbootproject.temptableuse.mapper;


import com.li.springbootproject.domain.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;

import java.util.List;
import java.util.Map;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 10/12/2022 11:07 AM
 */
@Mapper
public interface OracleMapper {

    /**
     * 执行 sql
     *
     * @param sql sql
     */
    @UpdateProvider(value = OracleProvider.class, method = "executeSql")
    void executeSql(String sql);

    @Insert("<script>INSERT INTO tempuser\n" +
            "        (id,requestid,code,columnname,datatype) " +
            "        <foreach collection=\"list\" item=\"item\" separator=\"UNION ALL\">\n" +
            "            select #{item.id}, #{item.requestId}, #{item.code}, #{item.columnName},#{item.dataType} from dual " +
            "        </foreach></script>")
    void insertBatch(List<User> list);

    @Select("${sql}")
    List<Map<String, Object>> listSql(String sql);

    /**
     * Mybatis Provider
     */
    class OracleProvider {
        public String executeSql(String sql) {
            return sql;
        }
    }
}
